<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="/javascripts/socket.io.js"></script>
</head>
<body>
<ul id="message"></ul>
<script>
    let userId = JSON.parse(getCookie("user")).id;
    socket = io.connect();

    socket.on("connect", function() {
        socket.emit("join", userId);
    });
    socket.on("getout", function(obj) {
        alert("我被踢飞了！");
    });

    function getCookie(name)
    {
        var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");

        if(arr=document.cookie.match(reg))

            return unescape(arr[2]);
        else
            return null;
    }
</script>
</body>
</html>